/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DSB.View;

import DSB.Controller.ToeristController;
import DSB.GPS.GPSController;
import DSB.Model.Kaart.Enums.ItemChanged;
import DSB.Utilities.Utilities;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;

/**
 *
 * @author Gebruiker
 */
public class Hoofdscherm extends javax.swing.JFrame implements Observer {

    Observable toeristObservable;
    Observable GPSObservable;
    private static ToeristController _toerist;
    private static Hoofdscherm scherm;
    private final Instellingenscherm _instellingen;
    private JPanel MapPanel;

    /**
     * Creates new form Test
     */
    public Hoofdscherm() {
        initComponents();
        _toerist = ToeristController.getInstance();
        _instellingen = new Instellingenscherm(this);
        _instellingen.setVisible(true);
        jTextField1.setText(_toerist.getLanguage());
        jTextField2.setText(_toerist.GetMeetEenheidName());

        MapPanel = new JPanel(new BorderLayout());
        MapPanel.setBounds(15, 15, 0, 0);
        this.add(MapPanel);

        toeristObservable = ToeristController.getInstance();
        GPSObservable = GPSController.getInstance();
        toeristObservable.addObserver(this);
        GPSObservable.addObserver(this);

        //DSBTitle.setText(_toerist.GetResource("DSBTitle"));
        //DSBDescription.setText(_toerist.GetResource("DSBDescription"));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        InfoArea = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        CloseItem = new javax.swing.JMenuItem();
        OptionsMenu = new javax.swing.JMenu();
        OptionsItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("DSB");
        setBounds(new java.awt.Rectangle(50, 50, 0, 0));
        setName("DSBFrame");

        InfoArea.setColumns(20);
        InfoArea.setRows(5);
        InfoArea.setEnabled(false);
        jScrollPane2.setViewportView(InfoArea);

        FileMenu.setText("Bestand");
        FileMenu.setName("FileMenu");

        CloseItem.setText("Afsluiten");
        CloseItem.setName("CloseItem");
        CloseItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                CloseItemMousePressed(evt);
            }
        });
        FileMenu.add(CloseItem);

        jMenuBar1.add(FileMenu);

        OptionsMenu.setText("Opties");
        OptionsMenu.setName("OptionsMenu");

        OptionsItem.setText("Opties");
        OptionsItem.setName("OptionsItem");
        OptionsItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                OptionsItemMousePressed(evt);
            }
        });
        OptionsMenu.add(OptionsItem);

        jMenuBar1.add(OptionsMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(415, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                    .addComponent(jTextField2)
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void OptionsItemMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_OptionsItemMousePressed
        _instellingen.setVisible(!_instellingen.isVisible());
    }//GEN-LAST:event_OptionsItemMousePressed

    private void CloseItemMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CloseItemMousePressed
        this.dispose();
    }//GEN-LAST:event_CloseItemMousePressed

    /**
     *
     */
    public void DrawMap() {
        BufferedImage map = _toerist.getMap();
        if (map != null) {
            for (int i = 0; i < MapPanel.getComponentCount(); i++) {
                MapPanel.remove(i);
            }

            JLabel lblImage = new JLabel(new ImageIcon(map));
            MapPanel.add(lblImage);
            MapPanel.setBounds(15, 15, map.getWidth(), map.getHeight());
            MapPanel.updateUI();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Hoofdscherm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Hoofdscherm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Hoofdscherm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Hoofdscherm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                scherm = new Hoofdscherm();
                scherm.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem CloseItem;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JTextArea InfoArea;
    private javax.swing.JMenuItem OptionsItem;
    private javax.swing.JMenu OptionsMenu;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

    /**
     *
     * @return
     */
    public static Hoofdscherm getInstance() {
        return scherm;
    }

    @Override
    public void update(Observable obs, Object arg) {
        if (obs instanceof ToeristController) {
            ToeristController toeristController = (ToeristController) obs;

            ItemChanged changed = toeristController.getChange();

            switch (changed) {
                case LANGUAGE:
                    Utilities.TranslateScreen(this);
                    break;
                case METRIC:
                    jTextField2.setText(toeristController.GetMeetEenheidName());
                    break;
            }
        }
        
        if (obs instanceof GPSController)
        {
            
        }
    }
}
